package telco.Client.Test;

import java.net.URI;
import java.util.Vector;

import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;

import telco.provider.beans.ProviderRegistrationStatus;
import telco.provider.service.ProviderService;
import swa2012.telco.broker.beans.Message;
import swa2012.telco.broker.beans.Client;
import swa2012.telco.broker.beans.Provider;

public class TestClient {
	
	public static void main(String args[]) {

	      JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();

	      factory.setServiceClass(ProviderService.class);
	      factory.setAddress("http://localhost:8080/Provider/ProviderService");
	      ProviderService provider = (ProviderService) factory.create();
	      
	      System.out.println("Ping Result: " + Boolean.toString(provider.ping()));
	      
	      Client c = new Client("Test", new Provider("20", URI.create("http://localhost:8080/Provider/ProviderService")));
	      
	      if(provider.registerClient(c) == ProviderRegistrationStatus.REGISTRATION_OK)
	      {
	    	  System.out.println("Registration successful!");
	      }
	      else System.out.println("Registration NOT successful!");
	     	      
	      try{
	      System.out.println("Clients: " + provider.listClients().toString());
	      }
	      catch(NullPointerException e)
	      {
	    	  System.out.println("No Clients anymore!");
	      }
	      
	      provider.receiveMessage(new Message(c, c, "Hallo das ist ein Test!", System.currentTimeMillis() / 1000));
	      
	      System.out.println(provider.getMessagesForClient(c).toString());
	      
	      ProviderRegistrationStatus result = provider.deregisterClient(c);	      
	      if(result == ProviderRegistrationStatus.REGISTRATION_OK)
	      {
	    	  System.out.println("De-Registration successful!");
	      }
	      else System.out.println("De-Registration NOT successful!");
	      
	      try{
	    	  System.out.println("Clients: " + provider.listClients().toString());
	      }
	      catch(NullPointerException e)
	      {
	    	  System.out.println("No Clients anymore!");
	      }
	    }
	
}
